package com.example.yiwei.crm.view.activity.jtCustomer;

import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.FragmentTabHost;
import android.support.v7.app.AppCompatActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TabHost;
import android.widget.TextView;

import com.example.yiwei.crm.R;
import com.example.yiwei.crm.view.frament.JDCoorFragment.EnteringFragment;
import com.example.yiwei.crm.view.frament.JDCoorFragment.QueryFragment;
import com.example.yiwei.crm.view.frament.JDCoorFragment.TJFragment;
import com.example.yiwei.crm.view.frament.menuFragment.crm_fragment;
import com.example.yiwei.crm.view.frament.menuFragment.home_fragment;
import com.example.yiwei.crm.view.frament.menuFragment.personal_information_fragment;

public class JDcoorActivity extends AppCompatActivity{
    TextView tv1,tv2,tv3,tv4;
    TextView tv[] = {tv1,tv2,tv3,tv4};
    private FragmentTabHost fragmentTabHost;
    //定义一个布局

    private LayoutInflater layoutInflater;
    private String texts[] = { "录入", "查询", "统计", "我" };
    private int imageButton[] = {R.drawable.bt_work_selectoe, R.drawable.find_select, R.drawable.bt_crm_selector,
            R.drawable.bt_personal_selector};
    private Class framentArray[]={EnteringFragment.class, QueryFragment.class, TJFragment.class,
            personal_information_fragment.class};
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_jdcoor);
        layoutInflater = LayoutInflater.from(this);
        fragmentTabHost = (FragmentTabHost) findViewById(android.R.id.tabhost);
        fragmentTabHost.setup(this,getSupportFragmentManager(), R.id.jd_coor_framely);
        for (int i = 0; i < texts.length; i++) {
            TabHost.TabSpec spec = fragmentTabHost.newTabSpec(texts[i]).setIndicator(getView(i));
            fragmentTabHost.addTab(spec, framentArray[i], null);
            //设置背景(必须在addTab之后，由于需要子节点（底部菜单按钮）否则会出现空指针异常)
            fragmentTabHost.getTabWidget().getChildAt(i).setBackgroundResource(R.drawable.bt_selector);
        }
        tv[0].setTextColor(Color.parseColor("#55ACEE"));
        fragmentTabHost.setOnTabChangedListener(new TabHost.OnTabChangeListener() {
            @Override
            public void onTabChanged(String s) {
                for (int i = 0; i < texts.length; i++) {
                    if (s.equals(texts[i])) {
                        tv[i].setTextColor(Color.parseColor("#55ACEE"));
                    } else {
                        tv[i].setTextColor(Color.parseColor("#A7A7A7"));
                    }
                }


            }
        });
        if ("ii".equals(getIntent().getStringExtra("ii"))){
            fragmentTabHost.setCurrentTab(1);
        }
        if ("tt".equals(getIntent().getStringExtra("tt"))){
            fragmentTabHost.setCurrentTab(2);
        }
        if ("me".equals(getIntent().getStringExtra("me"))){
            fragmentTabHost.setCurrentTab(3);
        }
    }
    private View getView(int i){
        View view = layoutInflater.inflate(R.layout.layout_item,null);
        ImageView im = (ImageView) view.findViewById(R.id.item_image);
        im.setImageResource(imageButton[i]);
        tv[i] = (TextView) view.findViewById(R.id.item_textview);
        tv[i].setText(texts[i]);
        TextView tv2 = (TextView) view.findViewById(R.id.tab_indicator_unread);
        tv2.setVisibility(View.GONE);
        return view;
    }
}
